#include "../source/http/http_server.h"
#include <iostream>

void test_http_server()
{
    framework::http::HttpServer::ptr server(new framework::http::HttpServer);
    framework::Address::ptr addr = framework::Address::LookupAnyIPAddress("0.0.0.0:8022");
    while(!server->bind(addr))
    {
        std::cout << "wait..." << std::endl;
        sleep(2);
    }

    auto sd = server->getServletDispatch();
    sd->addServlet("/lightning/xx", [](framework::http::HttpRequest::ptr request
                            , framework::http::HttpResponse::ptr response
                            , framework::http::HttpSession::ptr session){
        response->setBody(request->toString());
        return 0;               
    });

    sd->addGlobServlet("/lightning/*", [](framework::http::HttpRequest::ptr request
                        , framework::http::HttpResponse::ptr response
                        , framework::http::HttpSession::ptr session){
        response->setBody("Glob:\n\r" + request->toString());
        return 0;               
    });
    server->start();
}

int main(void)
{
    framework::IOManager iom(2);
    iom.schedule(test_http_server);

    return 0;
}